package com.example.mypotiota_si.Adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.mypotiota_si.Activity.DianPuActivity;
import com.example.mypotiota_si.Datas.Dianpu;
import com.example.mypotiota_si.Datas.MainActivity_Shop_date;
import com.example.mypotiota_si.R;

import java.util.ArrayList;

public class StaggerAdapter_sy_dp extends RecyclerView.Adapter<StaggerAdapter_sy_dp.ViewHolder> {
    private ArrayList<MainActivity_Shop_date> dianpu;
    Context context;
    ArrayList<String> strings;
    public StaggerAdapter_sy_dp(ArrayList<String> strings,ArrayList<MainActivity_Shop_date> dianpu,Context context) {
        this.strings=strings;
        this.context=context;
        this.dianpu = dianpu;
    }

    @NonNull
    @Override
    public StaggerAdapter_sy_dp.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view=View.inflate(parent.getContext(), R.layout.item_dp_stagger_view,null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull StaggerAdapter_sy_dp.ViewHolder holder, int position) {

        String name=dianpu.get(position).getName();
        String address=dianpu.get(position).getAddress();
        String yueshou=dianpu.get(position).getYueshou();
        String heart=dianpu.get(position).getHeart();


        //设置控件数据
        Glide.with(context).load(address).placeholder(R.mipmap.emei_looper1).into(holder.icon);
        holder.name.setText(name);
        holder.pf.setText("评分"+heart);
        holder.ys.setText("|月售"+yueshou);


        holder.cardView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context, DianPuActivity.class);
                intent.putExtra("name",dianpu.get(position).getName());
                intent.putExtra("address",dianpu.get(position).getAddress());
                intent.putExtra("heart",dianpu.get(position).getHeart());
                intent.putExtra("yueshou",dianpu.get(position).getYueshou());
                intent.putExtra("shop_address",dianpu.get(position).getShop_address());
                intent.putExtra("shop_Delivery_time",dianpu.get(position).getShop_Delivery_time());
                intent.putExtra("shop_qisong",dianpu.get(position).getShop_qisong());
                intent.putExtra("shop_gonggao",dianpu.get(position).getShop_gonggao());
                intent.putExtra("shop_peisongfei",dianpu.get(position).getShop_peisongfei());
                intent.putExtra("dates",dianpu.get(position).getDates());
                context.startActivity(intent);

            }
        });
    }

    @Override
    public int getItemCount() {
        if (dianpu!=null){
            return dianpu.size();
        }
        return 0;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView icon;
        private TextView name,pf,ys;
        CardView cardView;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            icon=itemView.findViewById(R.id.item_dp_icon);
            name=itemView.findViewById(R.id.item_dp_name);
            pf=itemView.findViewById(R.id.item_dp_pf);
            ys=itemView.findViewById(R.id.item_dp_ys);
            cardView=itemView.findViewById(R.id.dp_card_view);
        }

//        public void setData(Dianpu dianpu) {
//            icon.setImageResource(dianpu.dp_icon);
//            name.setText(dianpu.dp_name);
//            pf.setText("评分"+dianpu.dp_pf);
//            ys.setText("|月售"+dianpu.dp_ys);
//        }
    }
}
